package objects.cluster;

import objects.ObjectCodes;

import com.google.gson.Gson;


public class ClusterData implements ObjectCodes {
	public String hostname;
	public String local_hostname;
	public int nodes;
	public int procs;
	public int rjobs;
	public int qjobs;
	public int db_id;
	public boolean isOn;
	
	public ClusterData(){}
	
	public ClusterData(ClusterInfo cf)
	{
		this.hostname = cf.hostname;
		this.local_hostname = cf.local_hostname;
		this.db_id = cf.db_id;
		this.isOn = cf.isConnected;
	}
	public ClusterData(String h, String lh, int i, boolean io)
	{
		this.hostname = h;
		this.local_hostname = lh;
		this.db_id = i;
		this.isOn = io;
	}
	
	public void setCurrentClusterStatus()
	{
		int [] data = database.Database.getCurrentClusterStatus(db_id);
		if(data.length == 4) {
			nodes = data[0];
			procs = data[1];
			rjobs = data[2];
			qjobs = data[3];
		}
	}
	
	public String toString()
	{
		return new Gson().toJson(this);
	}
	
	public static ClusterData fromJSon(String json)
	{
		return new Gson().fromJson(json,ClusterData.class);
	}

}
